import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_page/mine_business/mine_setting/mine_scan_login_controller.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

class MineScanLoginPage extends StatefulWidget {
  static const routeName = '/mine/scan_login';
  const MineScanLoginPage({super.key});

  @override
  State<MineScanLoginPage> createState() => _MineScanLoginPageState();
}

class _MineScanLoginPageState extends State<MineScanLoginPage> {
  final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
  @override
  Widget build(BuildContext context) {
    return GetBuilder<MineScanLginController>(
      init: MineScanLginController(),
      builder: (controller) => Scaffold(
        extendBodyBehindAppBar: true,
        appBar: AppBar(
          elevation: 0,
          iconTheme: IconThemeData(color: Colors.white),
          backgroundColor: Colors.transparent,
          title: Text(
            '扫码登录',
            style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w500),
          ),
        ),
        body: Stack(
          children: [
            QRView(
              key: qrKey,
              onQRViewCreated: controller.onQRViewCreated,
              overlay: QrScannerOverlayShape(
                  overlayColor: Colors.black,
                  borderColor: Colors.white,
                  borderRadius: 0,
                  borderLength: 20,
                  borderWidth: 5,
                  cutOutSize: 235),
            ),
            Positioned(
              bottom: 100,
              left: 0,
              right: 0,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Expanded(
                    child: GestureDetector(
                      onTap: controller.openNativePhoto,
                      child: Column(
                        children: [
                          Image.asset(
                            'scan_photo.png'.mineImgPath,
                            width: 48,
                            height: 48,
                          ),
                          12.sizeBoxH,
                          Text(
                            '相册',
                            style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w500),
                          )
                        ],
                      ),
                    ),
                  ),
                  Expanded(
                    child: GestureDetector(
                      onTap: controller.jumpToCertificate,
                      child: Column(
                        children: [
                          Image.asset(
                            'mine_id.png'.mineImgPath,
                            width: 48,
                            height: 48,
                          ),
                          12.sizeBoxH,
                          Text(
                            '我的凭证',
                            style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w500),
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
